#!/bin/sh
#
# This is the script for generating files for a specific Dalton test job.
#
# For the .check file ksh or bash is preferred, otherwise use sh
# (and hope it is not the old Bourne shell, which will not work)
#
if [ -x /bin/ksh ]; then
   CHECK_SHELL='#!/bin/ksh'
elif [ -x /bin/bash ]; then
   CHECK_SHELL='#!/bin/bash'
else
   CHECK_SHELL='#!/bin/sh'
fi


#######################################################################
#  TEST DESCRIPTION
#######################################################################
cat > rsp_soppapolarsymm.info <<'%EOF%'
   rsp_soppapolarsymm
   ------------------
   Molecule:         H2O
   Wave Function:    MP2 (SOPPA) / cc-pVDZ
   Test Purpose:     Polarizability and C6/C8. Symmetry
%EOF%

#######################################################################
#  MOLECULE INPUT
#######################################################################
cat > rsp_soppapolarsymm.mol <<'%EOF%'
BASIS
cc-pVDZ
SOPPA singlet properties with symmetry.

    2    2  X  Z
        8.    1
O     0.0 -0.2249058930 0.0
        1.    1
H     1.45235 0.899623 0.0
%EOF%

#######################################################################
#  DALTON INPUT
#######################################################################
cat > rsp_soppapolarsymm.dal <<'%EOF%'
**DALTON INPUT
.RUN RESPONSE
**INTEGRALS
.DIPLEN
.DIPVEL
**WAVE FUNCTION
.HF
.MP2
**RESPONSE
.S0MIX
.SOPPA
*LINEAR
.DIPLEN
.FREQUE
 2
0.0 0.0592
*C6
.DIPLEN
.PRINT
  5
.MAXMOM
  6
.THCC6
 1.0D-4
**END OF DALTON INPUT
%EOF%
#######################################################################



#######################################################################

#######################################################################
#  CHECK SCRIPT
#######################################################################
echo $CHECK_SHELL >rsp_soppapolarsymm.check
cat >>rsp_soppapolarsymm.check <<'%EOF%'
log=$1

if [ `uname` = Linux ]; then
   GREP="egrep -a"
else
   GREP="egrep"
fi

if $GREP -q "not implemented for parallel calculations" $log; then
   echo "TEST ENDED AS EXPECTED"
   exit 0
fi

# Basis set
CRIT1=`$GREP "O * 1 * 8\.0000 * 26 * 14 * \[9s4p1d\|3s2p1d\]" $log | wc -l`
CRIT2=`$GREP "H * 2 * 1\.0000 * 7 * 5 * \[4s1p\|2s1p\]" $log | wc -l`
CRIT3=`$GREP "total\: * 3 * 10\.0000 * 40 * 24" $log | wc -l`
CRIT4=`$GREP "Spherical harmonic basis used\." $log | wc -l`
TEST[1]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4`
CTRL[1]=4
ERROR[1]="BASIS SET NOT READ CORRECTLY"

# Geometry
CRIT1=`$GREP "Total number of coordinates\: * 9" $log | wc -l`
CRIT2=`$GREP "1 * x * (0| )\.0000000000" $log | wc -l`
CRIT3=`$GREP "2 * y * (\-0|\-)\.2249058930" $log | wc -l`
CRIT4=`$GREP "3 * z * (0| )\.0000000000" $log | wc -l`
CRIT5=`$GREP "4 * x * 1\.4523500000" $log | wc -l`
CRIT6=`$GREP "5 * y * (0| )\.8996230000" $log | wc -l`
CRIT7=`$GREP "6 * z * (0| )\.0000000000" $log | wc -l`
CRIT8=`$GREP "7 * x * \-1\.4523500000" $log | wc -l`
CRIT9=`$GREP "8 * y * (0| )\.8996230000" $log | wc -l`
CRIT10=`$GREP "9 * z * (0| )\.0000000000" $log | wc -l`
TEST[2]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6 \+ \
		$CRIT7 \+ $CRIT8 \+ $CRIT9 \+ $CRIT10`
CTRL[2]=10
ERROR[2]="GEOMETRY NOT READ CORRECTLY"

# Energies
CRIT1=`$GREP "Hartree\-Fock total energy *\: * \-76\.02568148" $log | wc -l`
CRIT2=`$GREP "\= MP2 second order energy *\: * \-76\.2306668" $log | wc -l`
TEST[3]=`expr	$CRIT1 \+ $CRIT2`
CTRL[3]=2
ERROR[3]="ENERGIES NOT CORRECT"

# Static polarizabilites
CRIT1=`$GREP "\@.*YDIPLEN .* YDIPLEN .* 5\.50008.*(D|E)\+00" $log | wc -l`
TEST[4]=`expr	$CRIT1`
CTRL[4]=1
ERROR[4]="STATIC POLARIZABILITIES NOT CORRECT"

# Frequency dependEnt polarizabilites
CRIT1=`$GREP "\@ *a\.u\.\: * 5\.9200000(D|E)\-02" $log | wc -l`
CRIT2=`$GREP "\@.*YDIPLEN .* YDIPLEN .* 5\.56057.*(D|E)\+00" $log | wc -l`
TEST[5]=`expr	$CRIT1 \+ $CRIT2`
CTRL[5]=4
ERROR[5]="FREQUENCY DEPENDENT POLARIZABILITIES NOT CORRECT"

# Static C6/C8 polarizabilities
CRIT1=`$GREP "XDIPLEN * XDIPLEN .* 7\.3966[89]" $log | wc -l`
CRIT2=`$GREP "YDIPLEN * YDIPLEN .* 5\.50008" $log | wc -l`
CRIT3=`$GREP "ZDIPLEN * ZDIPLEN .* 3\.20692" $log | wc -l`
TEST[6]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3`
CTRL[6]=21
ERROR[6]="STATIC C6/C8 POLARIZABILITIES NOT CORRECT"

# Cauchy moments
CRIT1=`$GREP " 0 * 3\.20692..*(D|E)\+00" $log | wc -l`
CRIT2=`$GREP " 2 * 1\.22887..*(D|E)\+01" $log | wc -l`
CRIT3=`$GREP " 4 * 1\.40520..*(D|E)\+02" $log | wc -l`
CRIT4=`$GREP " 6 * 1\.72246..*(D|E)\+03" $log | wc -l`
CRIT5=`$GREP " 8 * 2\.1201..*(D|E)\+04" $log | wc -l`
CRIT6=`$GREP "10 * 2\.610..*(D|E)\+05" $log | wc -l`
CRIT7=`$GREP "12 * 3\.214..*(D|E)\+06" $log | wc -l`
CRIT8=`$GREP "14 * 3\.958..*(D|E)\+07" $log | wc -l`
CRIT9=`$GREP "16 * 4\.874..*(D|E)\+08" $log | wc -l`
CRIT10=`$GREP "18 * 6\.002..*(D|E)\+09" $log | wc -l`
CRIT11=`$GREP "20 * 7\.391..*(D|E)\+10" $log | wc -l`
CRIT12=`$GREP "22 * 9\.10[12]..*(D|E)\+11" $log | wc -l`
CRIT13=`$GREP "24 * 1\.120..*(D|E)\+13" $log | wc -l`
CRIT14=`$GREP "26 * 1\.380..*(D|E)\+14" $log | wc -l`
CRIT15=`$GREP "28 * 1\.699..*(D|E)\+15" $log | wc -l`
CRIT16=`$GREP "30 * 2\.092..*(D|E)\+16" $log | wc -l`
CRIT17=`$GREP "32 * 2\.57[67]..*(D|E)\+17" $log | wc -l`
CRIT18=`$GREP "34 * 3\.173..*(D|E)\+18" $log | wc -l`
CRIT19=`$GREP "36 * 3\.907..*(D|E)\+19" $log | wc -l`
CRIT20=`$GREP "38 * 4\.81[12]..*(D|E)\+20" $log | wc -l`
TEST[7]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6 \+ \
		$CRIT7 \+ $CRIT8 \+ $CRIT9 \+ $CRIT10 \+ $CRIT11 \+ $CRIT12 \+ \
		$CRIT13 \+ $CRIT14 \+ $CRIT15 \+ $CRIT16 \+ $CRIT17 \+ $CRIT18 \+ \
		$CRIT19 \+ $CRIT20`
CTRL[7]=20
ERROR[7]="CAUCHY MOMENTS NOT CORRECT"

PASSED=1
for i in 1 2 3 4 5 6 7
do
   if [ ${TEST[i]} -ne ${CTRL[i]} ]; then
     echo "${ERROR[i]} ( test = ${TEST[i]}; control = ${CTRL[i]} ); "
     PASSED=0
   fi
done

if [ $PASSED -eq 1 ]
then
  echo TEST ENDED PROPERLY
  exit 0
else
  echo THERE IS A PROBLEM
  exit 1
fi

%EOF%
#######################################################################
